﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="../scripts/boot.js" type="text/javascript"></script>
    <script type="text/javascript">
        $.ajax({
            url: "../data/system.aspx?method=1401",
            async: false,
            success: function (text) {
                if (text == "no")
                    window.location = "../system/error.html";
                else if (text == "out") {
                    var loginWindow = parent.mini.get("loginWindow");
                    if (!loginWindow.visible)
                        loginWindow.show();
                    var tabs = parent.mini.get("mainTabs");
                    var tab = tabs.getTab("tab$1401");
                    tabs.removeTab(tab);
                }
            }
        });
    </script>
</head>
<body>
    <div class="mini-toolbar" style="border-bottom: 0;">
        <table>
            <tr>
                <td>
                    名称：
                    <input class="mini-textbox" id="key" style="width:150px" emptytext="用户名或真实姓名关键字" />
                    类型：
                    <a class="mini-button" iconcls="icon-search" plain="true" onclick="search();">查询</a>
                    <span class="separator"></span>
                    <a class="mini-button" iconcls="icon-add" plain="true" onclick="sendRow()">发送短信</a>
                </td>
            </tr>
        </table>
    </div>
    <div class="mini-fit" >
        <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" allowresize="true"
            idfield="id" multiselect="true" url="../data/system.aspx?method=GetFindWorkList" sizeList="[15,20,50,100]" pageSize="15">
            <div property="columns">
                <div type="checkcolumn"></div>
                <div field="pi_user" headeralign="center" align="center" allowsort="true">
                    账号</div>
                <div field="pi_name" headeralign="center" align="center" allowsort="true">
                    真实姓名</div>
                <div field="fw_mobile" width="100px" headeralign="center" align="center" allowsort="true">
                    手机号码</div>
                <div field="fw_count" width="100px" headeralign="center" align="center" allowsort="true" renderer="onCountRenderer">
                    发送短信数</div>
            </div>
        </div>
    </div>
    <div id="editWindow" class="mini-window" title="手机短信" style="width: 400px;" showmodal="true"
        allowresize="false" allowdrag="true" showFooter="true">
        <div id="editform" class="form">
            <table style="width: 98%; height: 100%;">
                <tr style="height: 20px">
                    <td class="tdtitle" style="width: 60px;">
                        <span class="red">*</span>标题：
                    </td>
                    <td class="tdtext">
                        <input name="mm_title" class="mini-textbox" style="width:300px;" required="true"/>
                    </td>
                </tr>
                <tr style="height: 20px">
                    <td class="tdtitle">
                        <span class="red">*</span>内容：
                    </td>
                    <td class="tdtext">
                        <input class="mini-textarea" name="mm_memo" width="300px" height="100px" required="true"/>
                    </td>
                </tr>
            </table>
        </div>
        <div property="footer" style="text-align:center;padding:5px;">
            <a class="mini-button" style="width:60px;" onclick="updateRow()">保存</a>
            <span style="display:inline-block;width:25px;"></span>
            <a class="mini-button" style="width:60px;" onclick="closewin()">关闭</a>
        </div>
    </div>
    <script type="text/javascript">
        $.ajaxSetup({
            contentType: "application/x-www-form-urlencoded;charset=utf-8",
            complete: function (XMLHttpRequest, textStatus) {
                if (XMLHttpRequest.responseText == "out") {
                    var loginWindow = parent.mini.get("loginWindow");
                    if (!loginWindow.visible)
                        loginWindow.show();
                }
            }
        });

        mini.parse();

        var grid = mini.get("datagrid1");
        search();

        function search() {
            var key = mini.get("key").getValue();
            grid.load({ key: key });
            grid.sortBy("fw_pino", "desc");
        }

        function addRow() {
            var rows = grid.getSelecteds();
            if (rows.length > 0) {
                var form = new mini.Form("#editform");
                form.reset();
                form.loading();
                form.unmask();
                var win = mini.get("editWindow");
                win.setTitle("新增手机短信<span class='red'>( 带 * 号的必须填写)</span>");
                if (!win.visible)
                    win.show();
            }
            else
                ShowMessage("系统提示", "请选择需要发送手机短信的求职者！", 2);
        }

        function sendRow() {
            var rows = grid.getSelecteds();
            if (rows.length > 0) {
                var ids = "";
                for (var i = 0; i < rows.length; i++) {
                    ids += rows[i].fw_pino + ',';
                }
                mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '保存中，请稍后...' });
                $.ajax({
                    url: "../data/system.aspx?method=SendMobileMsgs",
                    type: "Post",
                    data: { id: ids },
                    success: function (ret) {
                        mini.unmask(document.body);
                        if (ret == "out") {
                            var loginWindow = parent.mini.get("loginWindow");
                            if (!loginWindow.visible)
                                loginWindow.show();
                            return;
                        }
                        if (ret >= 0) {
                            ShowMessage("系统提示", "手机短信发送成功！", 1);
                            grid.reload();
                        }
                        else
                            ShowMessage("系统提示", "手机短信发送失败！", 3);
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        mini.unmask(document.body);
                        ShowMessage("系统提示", "手机短信发送失败！", 3);
                    }
                });
            }
            else
                ShowMessage("系统提示", "请选择需要发送手机短信的求职者！", 2);
        }

        function updateRow() {
            var rows = grid.getSelecteds();
            if (rows.length > 0) {
                var ids = "";
                for (var i = 0; i < rows.length; i++) {
                    ids += rows[i].fw_pino + ',';
                }
                var form = new mini.Form("#editform");
                form.validate();
                if (form.isValid() == false)
                    return;
                var o = form.getData();
                var json = mini.encode(o);

                mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '保存中，请稍后...' });
                $.ajax({
                    url: "../data/system.aspx?method=SaveMobileMsgs",
                    type: "Post",
                    data: { data: json, id: ids },
                    success: function (ret) {
                        mini.unmask(document.body);
                        if (ret == "out") {
                            var loginWindow = parent.mini.get("loginWindow");
                            if (!loginWindow.visible)
                                loginWindow.show();
                            return;
                        }
                        var editWindow = mini.get("editWindow");
                        if (ret >= 0) {
                            editWindow.hide();
                            ShowMessage("系统提示", "手机短信发送成功！", 1);
                            grid.reload();
                        }
                        else
                            ShowMessage("系统提示", "手机短信发送失败！", 3);
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        mini.unmask(document.body);
                        ShowMessage("系统提示", "手机短信发送失败！", 3);
                    }
                });
            }
            else
                ShowMessage("系统提示", "请选择需要发送手机短信的求职者！", 2);
        }

        function onCountRenderer(e) {
            var s = e.value;
            if (e.value != null && e.value > 0)
                s = '<a class="linelink" title="详细" href="javascript:void(0);" onclick="messageRows(' + e.record._uid + ')">查看</a> (' + e.value + ')';
            return s;
        }

        //上传文件管理
        function messageRows(row_uid) {
            var row = grid.getRowByUID(row_uid);
            if (row) {
                var tabs = parent.mini.get("mainTabs");
                var tab = tabs.getTab("tab$1401");
                tab.enabled = false;
                showPTab(row.pi_no);
            }
        }

        //打开上传文件管理Tab
        function showPTab(pi_no) {
            var tabs = parent.mini.get("mainTabs");
            var id = "tab$msg" + pi_no;
            var tab = tabs.getTab(id);
            if (!tab) {
                tab = {};
                tab.name = id;
                tab.title = "手机短信查看";
                tab.showCloseButton = true;
                tab.url = "message/manage.html?method=1401&pino=" + pi_no;
                tabs.addTab(tab);
            }
            tabs.activeTab(tab);
        }

        function closewin() {
            var win = mini.get("editWindow");
            win.hide();
        }
    </script>
</body>
</html>